package com.wyp168.leetcode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class indexString {
    public static void main(String[] args) {

        String str = "leetcode";
        System.out.println(index(str));

    }

    public static int index(String s) {

        Map<Character,Integer> map = new HashMap<>();
        char[] chars = s.toCharArray();
        Set<Character> set = new HashSet<>();
        int setLength = 0;

        for (int i = 0;i<chars.length;i++) {
            set.add(chars[i]);
            if (!(setLength < set.size())) {
                return i;
            }
            setLength = set.size();
        }
        return -1;
    }
}
